package com.lsc.jdbc.demo.file.util;

import java.io.*;

public class IoTest_Utf8 {

    public static void main(String[] args) {


        /* 输出流 OutPut */
        try {
            File file = new File("D:\\info_utf8.txt");
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8");

            outputStreamWriter.append("花卷").append("hanamaki").append("123456");
            outputStreamWriter.close();
            fileOutputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        /* 输入流操作  */
        try {
            File file = new File("D:\\info_utf8.txt");
            String path = file.getPath();
            System.out.println(path);
            System.out.println(file.getName());
            FileInputStream fileInputStream = new FileInputStream(file);
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            /* 可变长字符串 */
            StringBuffer stringBuffer = new StringBuffer();
            while (inputStreamReader.ready()) {
                stringBuffer.append((char) inputStreamReader.read());
            }
            System.out.println(stringBuffer.toString());
            inputStreamReader.close();
            fileInputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
